/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.worsik.android.test.rideshare.util;

import android.content.Context;
import android.text.format.DateFormat;
import cz.worsik.android.test.rideshare.model.KalendarData;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author 231260
 */
public class KalendarTools {

	public static String mesice[] = {"month_january","month_february","month_march"
									,"month_april","month_may","month_june"
									,"month_july","month_august","month_september"
									,"month_october","month_november","month_december"};
	public static String dny[] = {"pondeli","utery","streda","ctvrtek","patek","sobota","nedele"};
	
	public static int getOldDaysInFirstWeek(Date datum)
	{
		Calendar kalendar = Calendar.getInstance();
		
		kalendar.setTime(datum);
		
		int den = 1;
		int mesic = kalendar.get(Calendar.MONTH);
		int rok = kalendar.get(Calendar.YEAR);
		
		Calendar cal = Calendar.getInstance();
		cal.set(rok, mesic, den);
		
		int position = cal.get(Calendar.DAY_OF_WEEK);
		if (position == Calendar.SUNDAY) {
			return 6;
		}
		else {
			return position - Calendar.MONDAY;
		}
	}	
	
	public static int getOldMonthDayCount(Date datum)
	{
		Calendar kalendar = Calendar.getInstance();
		
		kalendar.setTime(datum);
		kalendar.add(Calendar.MONTH, -1);
		
		int den = 1;
		int mesic = kalendar.get(Calendar.MONTH);
		int rok = kalendar.get(Calendar.YEAR);
		
		kalendar.set(rok, mesic, den);
		
		return kalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	
	public static int getNextDaysInLastWeek(Date datum)
	{
		Calendar kalendar = Calendar.getInstance();
		
		kalendar.setTime(datum);
		kalendar.add(Calendar.MONTH, 1);
		
		int den = 1;
		int mesic = kalendar.get(Calendar.MONTH);
		int rok = kalendar.get(Calendar.YEAR);
		
		Calendar cal = Calendar.getInstance();
		cal.set(rok, mesic, den);
		
		int position = cal.get(Calendar.DAY_OF_WEEK);
		
		if (position == Calendar.MONDAY) {
			return 0;
		}
		else if (position == Calendar.SUNDAY) {
			return 1;
		}
		else {
			return 9 - position;
		}
	}
	
	public static Date getDateOnPosition(Date datum, int position)
	{
		KalendarData kal = new KalendarData(datum);
		
		return kal.data.get(position);
	}
	
	public static Integer getDayOnPosition(Date datum, int position)
	{
		KalendarData kal = new KalendarData(datum);
		
		return kal.days.get(position);
	}
	
	public static Boolean getColorOnPosition(Date datum, int position)
	{
		KalendarData kal = new KalendarData(datum);
		
		return kal.colors.get(position);
	}
	
	public static String getTextForDateLabel(Context context, Date datum)
	{
		Calendar cal = Calendar.getInstance();
		cal.setTime(datum);
		
		String text = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());
		text += " "+DateFormat.getDateFormat(context).format(datum);
		
		return text;
	}
}
